<template>
  <el-dialog :title="title" :visible.sync="visible" width="1400px" append-to-body  @close="cancel">
  <el-card style="border-radius: 10px">
    <el-table v-loading="loading" :data="delayrecordList" @selection-change="handleSelectionChange">
      <el-table-column type="index" width="50" label="序号"/>
      <el-table-column label="产品物料编码" align="center" prop="itemCode" />
      <el-table-column label="产品物料名称" align="center" prop="itemName" />
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="单位" align="center" prop="unitOfMeasure" />
      <el-table-column label="入库批次号" align="center" prop="batchCode" />
<!--      <el-table-column label="仓库编码" align="center" prop="warehouseCode" />-->
      <el-table-column label="仓库" align="center" prop="warehouseName" >
        <template slot-scope="scope">
          <span>{{ scope.row.warehouseName}}/{{ scope.row.locationName}}/{{ scope.row.areaName}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="库区名称" align="center" prop="locationName" />
      <el-table-column label="库位名称" align="center" prop="areaName" />-->
      <el-table-column label="在库数量" align="center" prop="quantityOnhand" />
      <el-table-column label="生产日期" align="center" prop="manufactureDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.manufactureDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="质保期" align="center" prop="qualityGuaranteePeriod" />

      <el-table-column label="有效期" align="center" prop="expireDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expireDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="延迟日期" align="center" prop="delayDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.delayDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </el-card>
    <div slot="footer" class="dialog-footer" style="text-align:center;">
      <el-button type="primary" @click="cancel">取  消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listDelayrecord, getDelayrecord, delDelayrecord, addDelayrecord, updateDelayrecord } from "@/api/mes/wm/delayrecord";

export default {
  name: "delaydtail",
  props:{
    title:'',
  },
  data() {
    return {
      visible:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 有效期延期记录表格数据
      delayrecordList: [],

      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        materialStockId: null,        itemId: null,        itemCode: null,        itemName: null,        specification: null,        unitOfMeasure: null,        batchCode: null,        warehouseId: null,        warehouseCode: null,        warehouseName: null,        locationId: null,        locationCode: null,        locationName: null,        areaId: null,        areaCode: null,        areaName: null,        qualityGuaranteePeriod: null,        quantityOnhand: null,        manufactureDate: null,        expireDate: null,        delayDate: null,      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    init(stockId){
      this.visible=true
      this.queryParams.materialStockId=stockId
      this.getList()
    },
    /** 查询有效期延期记录列表 */
    getList() {
      this.loading = true;
      listDelayrecord(this.queryParams).then(response => {
        this.delayrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.queryParams.materialStockId=null
      this.reset();
      this.visible = false;
      this.$emit('refreshDataList')
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,        materialStockId: null,        itemId: null,        itemCode: null,        itemName: null,        specification: null,        unitOfMeasure: null,        batchCode: null,        warehouseId: null,        warehouseCode: null,        warehouseName: null,        locationId: null,        locationCode: null,        locationName: null,        areaId: null,        areaCode: null,        areaName: null,        qualityGuaranteePeriod: null,        quantityOnhand: null,        manufactureDate: null,        expireDate: null,        delayDate: null,        createBy: null,        createByName: null,        createTime: null,        updateBy: null,        updateByName: null,        updateTime: null,        tenantId: null      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },


    /** 导出按钮操作 */
    handleExport() {
      this.download('wm/delayrecord/export', {
        ...this.queryParams
      }, `delayrecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
